// run: $exec < input
#include <iostream>

int n;

int main()
{
	std::cin >> n;
	int ans = 0, p0 = 0, p1 = 0;
	for (int i = 0, x; i < n; i++, p1 = p0, p0 = x) {
		std::cin >> x;
		if (x == 1) {
			ans++;
			if (p0 == 0 && p1 == 1) ans++;
		}
	}
	std::cout << ans << '\n';
}

